package api.ttreward;

import android.app.Activity;

import java.lang.ref.SoftReference;

/**
 * 头条激励视频
 */
public abstract class Reward_API_TT {

    public static String clazz = "com.dotools.toutiaolibrary.TT_RewardVideo";

    private static SoftReference<Reward_API_TT> sf;

    public synchronized static Reward_API_TT getInstance() {

        if (sf == null || sf.get() == null) {
            Object o = null;
            try {
                o = Class.forName(clazz).newInstance();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
            if (o != null) {
                sf = new SoftReference<>((Reward_API_TT) o);
                return (Reward_API_TT) o;
            }
        }
        return sf == null ? null : sf.get();
    }

    /**
     * @param context      Activity
     * @param appid        程序id
     * @param adposid      广告id
     * @param userId       用户id
     * @param rewardName   奖励的名称
     * @param rewardAmount 奖励的数量
     * @param count        请求广告数量
     * @param isDebug      是否打开调试
     * @param orientation  视频的展示方向  1竖屏   2横屏
     * @param isExpress    是否是个性化模板广告
     * @param listener
     */
    public abstract void LoadTTReward(Activity context, String appid, String adposid, String userId, String rewardName, int rewardAmount, int count, int downloadMode,boolean isDebug, int orientation, boolean isExpress,final TTRewardListener listener);

    public interface TTRewardListener {
        //视频广告拉去成功
        void onLoaded();
        //视频广告展示回调
        void onShow();
        //广告的下载bar点击回调
        void onVideoBarClick();
        //视频广告关闭回调
        void onClose();

        //视频广告播放完毕回调
        void onVideoComplete();
        //视频广告播完验证奖励有效性回调，参数分别为是否有效，奖励数量，奖励名称
        void onRewardVerify(boolean var1, int var2, String var3);

        void onSkippedVideo();


        void onError(int code, String message);
    }
}